#include "stdafx.h"
#include "Analyze.h"
#include <wtypes.h>
#include "..\Parser.h"

BOOL paramter_list_desc_once()
{
	SymbolStack.Pop(); // as
	CLexer_Token_Ptr Name = SymbolStack.Pop();
	NAutoPtr<CSyntaxTreeNode> Type = ParserAnalyze.Pop();
	NAutoPtr<CSyntaxTreeNode> Node = new CSyntaxTreeNode(CSyntaxTreeNode::stParamterList,0);
	Node->Child().Add(Type);
	ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL paramter_list_desc_more()
{
	SymbolStack.Pop(); // as
	CLexer_Token_Ptr Name = SymbolStack.Pop();
	SymbolStack.Pop(); // operator ,
	NAutoPtr<CSyntaxTreeNode> Type = ParserAnalyze.Pop();
	ParserAnalyze.Top()->Child().Add(Type);
	return TRUE;
}

BOOL function_desc_first()
{
	CLexer_Token_Ptr Ptr = SymbolStack.Pop();
	SymbolStack.Pop();
	NAutoPtr<CSyntaxTreeNode> Node = new CSyntaxTreeNode(CSyntaxTreeNode::stFunction,0);
	Node->Child().Add(new CSyntaxTreeNode(CSyntaxTreeNode::stNull,0)); // function name node
	ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL function_desc_second()
{
	SymbolStack.Pop(); // operator )
	SymbolStack.Pop(); // operator (
	NAutoPtr<CSyntaxTreeNode> Node = ParserAnalyze.Pop();
	if(Node->Type() == CSyntaxTreeNode::stParamterList) // if have paramters the stFunction's lowest bit is 1
	{
		ParserAnalyze.Top()->Value() |= 1 << 0;
		ParserAnalyze.Top()->Child().Add(Node);
	}
	else ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL function_desc_third()
{
	SymbolStack.Pop(); // symbol as
	NAutoPtr<CSyntaxTreeNode> Type = ParserAnalyze.Pop();
	ParserAnalyze.Top()->Value() |= 1 << 1; // if have return the stFunction's second lowest bit is 1
	ParserAnalyze.Top()->Child().Add(Type);
	return TRUE;
}

BOOL function_desc_fourth()
{
	return TRUE;
}

BOOL function_desc_fifth()
{
	SymbolStack.Pop(); // symbol function
	SymbolStack.Pop(); // symbol end
	return TRUE;
}